package com.phenix.network.util

import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.Moshi
import java.lang.reflect.Type

object MoshiUtils {

    private val moshiBuilder: Moshi = Moshi.Builder().build()

    private fun <T> getAdapter(type: Type): JsonAdapter<T> = moshiBuilder.adapter(type)

    fun <T> fromJson(json: String, type: Type): T? = getAdapter<T>(type).fromJson(json)

    fun toJson(obj: Any): String? = moshiBuilder.adapter(Any::class.java).toJson(obj)

}

